// 不携带token的请求
import axios from 'axios'
import {  ElMessage } from 'element-plus'

const axiosReq = axios.create({
    baseURL : import.meta.env.VITE_APP_BASE_API,
    timeout : 10000,
})

axiosReq.interceptors.response.use(
    response => {
        if(response.status != 200){
            ElMessage({
                message: response.statusText,
                type: 'error',
                duration: 5 * 1000
            })
            return Promise.reject(new Error(response.statusText || 'Error'))
        }
        if(response.data.code != 200){
            ElMessage({
                message: response.data.msg,
                type: 'error',
                duration: 5 * 1000
            })
            return Promise.reject(new Error(response.data.msg || 'Error'))
        }

        return response.data
    },
    error => {
        console.log('req response error:' + error);
        return Promise.reject(error)
    }
)

export default axiosReq